package main

import "fmt"

func main() {
	arr := []int{1, 8, 6, 2, 5, 4, 8, 3, 7}
	max := maxArea(arr)
	fmt.Println(max)
}

func min(i, j int) int {
	if i < j {
		return i
	}
	return j
}
func maxArea(height []int) int{
	i, j, max := 0, len(height)-1, 0

	for i < j {
		tmp := (j - i) * min(height[i], height[j])
		if tmp > max {
			max = tmp
		}

		if height[i] < height[j] {
			i++
		} else {
			j--
		}
	}
	return max
}
